//
//  QKtestWKWebview.m
//  testTool
//
//  Created by Su on 2018/12/29.
//  Copyright © 2018 com.qiankun. All rights reserved.
//

#import "QKtestWKWebview.h"
#import <WebKit/WebKit.h>
@interface QKtestWKWebview ()

@property (nonatomic,strong) WKWebView   *webView;

@end

@implementation QKtestWKWebview
-(void)injected{
    [self setwkWebview];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self setwkWebview];
    


}

-(void)setwkWebview{
    if (self.webView) {
        [self.webView removeFromSuperview];
        self.webView = nil;
    }
    
    WKUserContentController* userContentController = WKUserContentController.new;
    WKUserScript * cookieScript = [[WKUserScript alloc] initWithSource:
                                   @"document.cookie = 'fromapp=ios';document.cookie = 'channel=appstore';" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO];
    [userContentController addUserScript:cookieScript];
    WKWebViewConfiguration* webViewConfig = WKWebViewConfiguration.new;
    webViewConfig.userContentController = userContentController;

    self.webView = [[WKWebView alloc]initWithFrame:CGRectZero configuration:webViewConfig];
    [self.view addSubview:self.webView];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.mas_equalTo(self.view);
    
    }];
    NSMutableURLRequest *request =
        [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://192.168.8.159:8080"]];
    [self.webView loadRequest:request];
   
}

@end
